package com.jic.veteran.portal.controller;

import com.github.pagehelper.PageInfo;
import com.google.common.collect.Maps;
import com.jic.veteran.common.api.CommonPage;
import com.jic.veteran.common.api.CommonResult;
import com.jic.veteran.model.*;
import com.jic.veteran.portal.domain.AlumniParamDto;
import com.jic.veteran.portal.domain.AlumniStudentInfoChangeParam;
import com.jic.veteran.portal.domain.AlumniStudentParam;
import com.jic.veteran.portal.domain.CmsArticleQueryParam;
import com.jic.veteran.portal.service.AlumniStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 获取学校相关信息接口
 * @author mars
 * @date 2021/11/10
 */
@RestController
@Api(tags = "AlumniStudentController",description = "校友信息")
@RequestMapping("/student")
public class AlumniStudentController {
  @Autowired
  private AlumniStudentService alumniStudentService;

  @ApiOperation("通讯录列表")
  @RequestMapping(value = "/allstudents", method = RequestMethod.POST)
  @ResponseBody
  public CommonResult<Map<String, List<AlumniSchoolAddresslist>>> getStudnetsList(@RequestBody AlumniStudentParam alumniStudentParam) {

    List<AlumniSchoolAddresslist> alumniSchoolAddresslist = alumniStudentService.getStudnetsList(alumniStudentParam);
    Map<String, List<AlumniSchoolAddresslist>> map = Maps.newHashMapWithExpectedSize(20);
    map.put("list", alumniSchoolAddresslist);
    return CommonResult.success(map);

  }

//  @ApiOperation("通讯录分页")
//  @RequestMapping(value = "/pagestudents", method = RequestMethod.POST)
//  @ResponseBody
//  public CommonResult<Map<String, List<AlumniSchoolAddresslist>>> getStudnetsListPage(
//          @RequestBody AlumniStudentParam alumniStudentParam,
//          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
//          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum
//  ) {
//
//    List<AlumniSchoolAddresslist> alumniSchoolAddresslist = alumniStudentService.getStudnetsListPage(alumniStudentParam,pageSize,pageNum);
//    Map<String, List<AlumniSchoolAddresslist>> map = Maps.newHashMapWithExpectedSize(20);
//    map.put("list", alumniSchoolAddresslist);
//    return CommonResult.success(map);
//  }


  @ApiOperation("通讯录分页")
  @RequestMapping(value = "/pagestudents", method = RequestMethod.POST)
  @ResponseBody
  public CommonResult<CommonPage<AlumniSchoolAddresslist>> getStudnetsListPage(
          @RequestBody AlumniStudentParam alumniStudentParam,
          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum
  ) {

    List<AlumniSchoolAddresslist> alumniSchoolAddresslist = alumniStudentService.getStudnetsListPage(alumniStudentParam,pageSize,pageNum);
    Map<String, List<AlumniSchoolAddresslist>> map = Maps.newHashMapWithExpectedSize(20);
    map.put("list", alumniSchoolAddresslist);
    return CommonResult.success(CommonPage.restPage(alumniSchoolAddresslist));

  }


  @ApiOperation("学生信息详情")
  @RequestMapping(value = "/studentdetail", method = RequestMethod.GET)
  @ResponseBody
  public CommonResult<AlumniSchoolAddresslist> getStudnetDetail(Long id) {

    AlumniSchoolAddresslist alumniSchoolAddresslist = alumniStudentService.getStudnetDetail(id);

    return CommonResult.success(alumniSchoolAddresslist);
  }


    @ApiOperation("小程序修改学生信息")
    @RequestMapping(value = "/change/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult changeInfo(@PathVariable Integer id,
                                   @RequestBody AlumniStudentInfoChangeParam alumniStudentInfoChangeParam
                                   ) {
        int count = alumniStudentService.changeInfo(id,alumniStudentInfoChangeParam);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }


  @ApiOperation("通讯录下拉框列表：1：年级；2：地区；3：行业；4：班级；")
  @RequestMapping(value = "/search/{type}", method = RequestMethod.POST)
  @ResponseBody
  public CommonResult<List<String>> searchParam(@PathVariable Integer type) {
    List<String> list = alumniStudentService.searchParam(type);

      return CommonResult.success(list);
  }

  @ApiOperation("更改头像")
  @RequestMapping(value = "/avatar", method = RequestMethod.POST)
  @ResponseBody
  public CommonResult changeAvatar(@RequestParam(value = "id", required=true) Integer id,
                                   @RequestParam(value = "avatarUrl", required=true) String avatarUrl) {
    int count = alumniStudentService.changeAvatar(id,avatarUrl);
    if (count > 0) {
      return CommonResult.success(count);
    }
    return CommonResult.failed();
  }


}
